from django.db import models
from ckeditor_uploader.fields import RichTextUploadingField


# Create your models here.
class User(models.Model):
    """ 用户表 """
    userId = models.AutoField(primary_key=True, verbose_name="用户ID", null=False, unique=True)
    username = models.CharField(max_length=50, verbose_name='用户名', unique=True)  # 添加label标签
    password = models.CharField(max_length=50, verbose_name='密码')
    name = models.CharField(max_length=50, verbose_name='昵称')
    phone = models.CharField(max_length=50, verbose_name="手机号")
    admin_type = models.CharField(max_length=20, verbose_name="管理类型", default="ordinary")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.username

    class Meta:
        db_table = 't_user'
        verbose_name_plural = '用户'


class Category(models.Model):
    """ 文章类别 """
    cname = models.CharField(max_length=30, verbose_name='文章类别', unique=True)
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')

    def __str__(self):
        return str(self.cname)

    class Meta:
        db_table = 't_category'
        verbose_name_plural = '文章类别'


class Article(models.Model):
    """ 文章内容 """
    title = models.CharField(max_length=100, unique=True, verbose_name='文章标题')
    desc = models.CharField(max_length=200, verbose_name='文章简介')
    content = RichTextUploadingField(verbose_name='文章内容')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    modified_time = models.DateTimeField(auto_now=True, verbose_name='修改时间')
    isdelete = models.BooleanField(default=False, verbose_name='是否删除')
    category = models.ForeignKey(to=Category, on_delete=models.CASCADE, verbose_name='文章类别')

    def __str__(self):
        return str(self.title)

    class Meta:
        db_table = 't_article'
        verbose_name_plural = '文章内容'


class Position(models.Model):
    """ 职位信息
        招聘公司信息：公司名称、公司简介、岗位需求等；
        招聘职位信息：岗位名称、岗位职能介绍、岗位评估（职位和未来的晋升空间）、任职资格、薪酬福利、招聘人数等；
        信息接收方式：联系人、联系方式（电话、电子邮箱）、公司地址、导航公交路线等。
     """
    corporation = models.CharField(max_length=100, verbose_name='公司名称')
    company_profile = models.CharField(max_length=300, verbose_name='公司简介')
    position_name = models.CharField(max_length=50, verbose_name='岗位名称')
    required_specialty = models.CharField(max_length=100, verbose_name='所需专业')
    position_profile = RichTextUploadingField(verbose_name='岗位简介')
    contact_name = models.CharField(max_length=20, verbose_name='联系人姓名')
    contact_address = models.CharField(max_length=100, verbose_name='联系地址')
    contact_number = models.CharField(max_length=100, verbose_name='联系电话')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')

    def __str__(self):
        return str(self.position_name)

    class Meta:
        db_table = 't_position'
        verbose_name_plural = '职位信息'
